package com.fdb.efp.nls.service.common.rules.apply;

import com.fdb.basic.framework.core.constant.EsbRetCodeStandard;
import com.fdb.basic.framework.core.exception.BizException;
import com.fdb.basic.framework.core.util.MessageRuleCheckUtil;
import com.fdb.efp.nls.service.common.rules.CheckRule;

import java.util.regex.Pattern;

/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2019/12/4
 * 功能描述:
 * 修改日期:2019/12/4
 * 修改描述:
 */
public class ValidateApplySeqRule implements CheckRule {
    public static final String APPLY_PREFIX = "YX";
    private String applySeq;

    public ValidateApplySeqRule(String applySeq) {
        this.applySeq = applySeq;
    }

    @Override
    public void check() throws BizException {
        if (!MessageRuleCheckUtil.checkDate(applySeq.substring(2, 16)).matches()) {
            throw new BizException(EsbRetCodeStandard.JKYDCSJYBTG.getValue(), "支用申请流水号格式不正确！");
        }
        String regex = APPLY_PREFIX + "[0-9]{20}";
        Pattern pattern = Pattern.compile(regex);
        if (!pattern.matcher(applySeq).matches()) {
            throw new BizException(EsbRetCodeStandard.JKYDCSJYBTG.getValue(), "支用申请流水号格式不正确！");
        }
    }
}
